package com.yhg.context.web;


import com.yhg.common.utils.R;
import com.yhg.context.entity.BlType;
import com.yhg.context.service.BlTypeService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 帖子类型表 前端控制器
 * </p>
 *
 * @author 白小白
 * @since 2021-02-01
 */
@RestController
@RequestMapping("/context/type")
@Api(description = "简单查询")
@CrossOrigin
public class BlTypeController {


    @Autowired
    BlTypeService typeService;

    /**
     * 查询所有分类
     */
    @GetMapping("list")
    public R listAll(){
        List<BlType> typeList = typeService.listAll();
        return R.ok().data("typeList",typeList);
    }

    /**
     * 根据id查询分类
     */
    @GetMapping("selectOneType/{id}")
    public R selectOneType(@PathVariable String id){
        BlType blogType = typeService.getById(id);
        return R.ok().data("blogType",blogType);
    }

    /**
     * 将类型封装成map
     */
    @GetMapping("getTypeMap")
    public R getTypeMap(){
        Map<String, Object> typeMap = typeService.getTypeMap();
        return R.ok().data("typeMap",typeMap);
    }


}

